package cn.cqie.frame.dto;

import cn.cqie.frame.utils.AssertUtil;
import cn.cqie.frame.vo.UserVo;

/**
 * @author xieyihong
 */
public class UserContext {

    private static ThreadLocal<UserVo> userThread = new ThreadLocal<>();

    public static void set(UserVo user) {

        userThread.set(user);
    }

    public static UserVo get() {
        UserVo userVo = userThread.get();
        AssertUtil.isNotNull(userVo, "用户未登录");
        return userVo;
    }

    //防止内存泄漏
    public static void remove() {
        userThread.remove();
    }
}
